<?php
namespace Waimai\Controller;
class SetController extends Controller {
	public function index() {
		if (IS_POST) {
			if (Db::table('shop') -> where('id', $_POST['id']) -> first()) {
				if (Db::table('shop') -> update($_POST)) {
					View::ajax(array('code' => 0, 'message' => '修改成功'));
				} else {

					View::ajax(array('code' => 1, 'message' => '设置失败'));
				}
			} else {
				if (Db::table('shop') -> insert($_POST)) {
					View::ajax(array('code' => 0, 'message' => '修改成功'));
				} else {

					View::ajax(array('code' => 1, 'message' => '设置失败'));
				}
			}

		} else {
			$field = Db::table('shop') -> first();

			View::with('field', $field);
			View::make();
		}
	}

}
